package com.qyer.search.model.sort;

/**
 * Created by tangzheng on 16/8/19.
 */
public class SortEntity implements Comparable<SortEntity>{
  private int id;
  private long factor;

  public SortEntity(int id, long factor) {
    this.id = id;
    this.factor = factor;
  }

  public SortEntity(int id) {
    this.id = id;
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public long getFactor() {
    return factor;
  }

  public void setFactor(long factor) {
    this.factor = factor;
  }

  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    SortEntity that = (SortEntity) o;

    if (id != that.id)
      return false;
    return factor == that.factor;

  }

  @Override public int hashCode() {
    int result = id;
    result = 31 * result + (int) (factor ^ (factor >>> 32));
    return result;
  }

  @Override public String toString() {
    return "SortEntity{" +
      "factor=" + factor +
      ", id=" + id +
      '}';
  }

  @Override public int compareTo(SortEntity sortEntity){
    long tmp = sortEntity.factor - this.factor;
    if(tmp < 0)
      return -1;
    else
      return 1;
  }

}
